import React, { useEffect, useState } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { Tabs } from "react-vant";
// const navigate = useNavigate();
// import './style.less'
import "../css/style.less";
import { Cell } from "react-vant";
import { List } from "react-vant";
import { policylist } from "../sevice/postQuery";
import { PullRefresh } from "react-vant";

// const items = Array.from({ length: 2 }, (_, i) => i + 1)

export default ({ list, postId }) => {
  const navigate = useNavigate();
  let [data1, setList] = useState([]); //数组
  const [finished, setFinished] = useState(false);
  useEffect(() => {
    (async () => {
      let { data } = await policylist({
        areaId: postId,
        pageSize: 5, //一个参数//首次请求5条数据
        pageNum: 1,
      }); //num表示的是页码。pagesize表示每页的数

      // console.log(data,"周斤");
      setList([...data?.data]);
    })();
  }, []);
  useEffect(() => {
    console.log(data1, "周两斤");
  }, [data1]);
  const onLoad = async () => {
    if (data1.length >= 5) {
      setFinished(true); //为true则加载
      let { data } = await policylist({
        areaId: postId,
        pageSize: 10,
        pageNum: 2,
      });
      let a = data?.data.splice(5, 10);
      console.log(a, "jijijiji");

      console.log(data.data, "李广");
      setList([...data1, ...a]);
    }
  };
  let btn = (id) => {
    console.log(id);
    navigate(`/post/${postId}/${id}`)
    console.log(99);
    window.localStorage.setItem("pocy",id)
// id需要传进去。我曹
    
  }
  return (
    <div className="demo-tabs">
      <Tabs defaultActive={1}>
        {/* {items.map(item => ( */}
        <Tabs.TabPane title={"简介"}>
          {/* <div>{list?.introduce}</div> */}
          <Cell value={list?.introduce} />
        </Tabs.TabPane>
        <Tabs.TabPane title={"人才政策"}>
          <List finished={finished} onLoad={onLoad}>
            {data1.map((item) => {
              return <Cell key={item.id} onClick={() => {
                btn(item.id)
              }}>{item.title}</Cell>;
            })}
          </List>
        </Tabs.TabPane>
        {/* ))} */}
      </Tabs>
    </div>
  );
};
